<template>
  <div ref="border6" class="border-wrap">
    <svg class="dv-border-svg-container" :width="width" :height="height">
      <defs>
        <filter :id="filterId" height="150%" width="150%" x="-25%" y="-25%">
          <feMorphology operator="dilate" radius="1" in="SourceAlpha" result="thicken" />
          <feGaussianBlur in="thicken" stdDeviation="2" result="blurred" />
          <feFlood :flood-color="fade(borderColor[1], 70)" result="glowColor">
            <animate
              attributeName="flood-color"
              :values="`
                ${fade(borderColor[1], 70)};
                ${fade(borderColor[1], 30)};
                ${fade(borderColor[1], 70)};
              `"
              dur="3s"
              begin="0s"
              repeatCount="indefinite"
            />
          </feFlood>
          <feComposite in="glowColor" in2="blurred" operator="in" result="softGlowColored" />
          <feMerge>
            <feMergeNode in="softGlowColored" />
            <feMergeNode in="SourceGraphic" />
          </feMerge>
        </filter>
      </defs>

      <path
        v-if="width && height"
        :fill="bgColor"
        stroke-width="2"
        :stroke="borderColor[0]"
        :d="`
          M15 5 L ${width - 15} 5 Q ${width - 5} 5, ${width - 5} 15
          L ${width - 5} ${height - 15} Q ${width - 5} ${height - 5}, ${width - 15} ${height - 5}
          L 15, ${height - 5} Q 5 ${height - 5} 5 ${height - 15} L 5 15
          Q 5 5 15 5
        `"
      />

      <path
        stroke-width="2"
        fill="transparent"
        stroke-linecap="round"
        :filter="`url(#${filterId})`"
        :stroke="borderColor[1]"
        :d="`M 20 5 L 15 5 Q 5 5 5 15 L 5 20`"
      />

      <path
        stroke-width="2"
        fill="transparent"
        stroke-linecap="round"
        :filter="`url(#${filterId})`"
        :stroke="borderColor[1]"
        :d="`M ${width - 20} 5 L ${width - 15} 5 Q ${width - 5} 5 ${width - 5} 15 L ${width - 5} 20`"
      />

      <path
        stroke-width="2"
        fill="transparent"
        stroke-linecap="round"
        :filter="`url(#${filterId})`"
        :stroke="borderColor[1]"
        :d="`
          M ${width - 20} ${height - 5} L ${width - 15} ${height - 5}
          Q ${width - 5} ${height - 5} ${width - 5} ${height - 15}
          L ${width - 5} ${height - 20}
        `"
      />

      <path
        stroke-width="2"
        fill="transparent"
        stroke-linecap="round"
        :filter="`url(#${filterId})`"
        :stroke="borderColor[1]"
        :d="`
          M 20 ${height - 5} L 15 ${height - 5}
          Q 5 ${height - 5} 5 ${height - 15}
          L 5 ${height - 20}
        `"
      />
    </svg>
  </div>
</template>

<script>
import { uuid } from '../util'
import { fade } from '../util/fade'
export default {
  props: {
    bgColor: {
      type: String,
      default: () => 'transparent'
    },
    borderColor: {
      type: Array,
      default: () => ['#2e6099', '#7ce7fd']
    },
    width: {
      type: Number,
      default: () => 0
    },
    height: {
      type: Number,
      default: () => 0
    }
  },
  data() {
    const id = uuid()
    return {
      filterId: `borderr-box-12-filterId-${id}`
    }
  },
  methods: {
    fade
  }
}
</script>

<style scoped="scoped" lang="less">
  .dv-border-svg-container {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0px;
    left: 0px;

    polyline {
      fill: none;
    }
  }
 .dv-reverse {
    transform: rotate(180deg);
  }

 .sw1 {
   stroke-width: 1;
 }

 .sw3 {
   stroke-width: 3px;
   stroke-linecap: round;
 }

 .dv-bb4-line-1 {
    stroke-width: 1;
 }

 .dv-bb4-line-2 {
    stroke-width: 1;
 }

 .dv-bb4-line-3 {
   stroke-width: 3px;
   stroke-linecap: round;
 }

 .dv-bb4-line-4 {
   stroke-width: 3px;
   stroke-linecap: round;
 }

 .dv-bb4-line-5 {
    stroke-width: 1;
 }

 .dv-bb4-line-6 {
    stroke-width: 1;
 }

 .dv-bb4-line-7 {
    stroke-width: 1;
 }

 .dv-bb4-line-8 {
   stroke-width: 3px;
   stroke-linecap: round;
 }

 .dv-bb4-line-9 {
   stroke-width: 3px;
   stroke-linecap: round;
   stroke-dasharray: 100 250;
 }

 .dv-bb4-line-10 {
    stroke-width: 1;
   stroke-dasharray: 80 270;
 }
</style>
